import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/data-entry'
    },
    {
      path: '/record-maintenance',
      name: 'RecordMaintenance',
      component: () => import('../pages/RecordMaintenance/RecordMaintenance.vue'),
      meta: {
        title: '记录维护',
        icon: 'Memo'
      }
    },
    {
      path: '/data-entry',
      name: 'DataEntry',
      component: () => import('../pages/DataEntry/DataEntryNew.vue'),
      meta: {
        title: '数据录入',
        icon: 'Edit'
      }
    },
    {
      path: '/target-management',
      name: 'TargetManagement',
      component: () => import('../pages/TargetManagement/TargetManagementNew.vue'),
      meta: {
        title: 'PPH目标值管理',
        icon: 'Setting'
      }
    },
    {
      path: '/estimate-management',
      name: 'EstimateManagement',
      component: () => import('../pages/EstimateManagement/EstimateManagementNew.vue'),
      meta: {
        title: 'PPH预估值管理',
        icon: 'TrendCharts'
      }
    },
    {
      path: '/reports',
      name: 'Reports',
      component: () => import('../pages/Reports/Reports.vue'),
      meta: {
        title: '报表分析',
        icon: 'DataLine'
      }
    },
    {
      path: '/settings',
      name: 'Settings',
      component: () => import('../pages/SystemSettings/SystemSettings.vue'),
      meta: {
        title: '系统设置',
        icon: 'Tools'
      }
    },
    {
      path: '/docs/calculation',
      name: 'CalculationGuide',
      component: () => import('../pages/Docs/CalculationGuide.vue'),
      meta: {
        title: '计算说明',
        icon: 'HelpFilled'
      }
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      component: () => import('../pages/NotFound.vue')
    }
  ]
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta?.title) {
    document.title = `${to.meta.title} - PPH系统`
  }
  next()
})

export default router
